package com.alpha.eceasy.mall.api.entity;

import com.alpha.eceasy.extension.BaseFormInfo;
import com.alpha.eceasy.mall.api.dto.MallCommoditySpecificationDTO;
import com.alpha.eceasy.mall.api.handler.ListStringHandler;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.beans.BeanUtils;

import java.io.Serial;
import java.math.BigDecimal;
import java.util.List;
import java.util.Optional;

/**
 * @author huangpengfei
 */
@Data
@TableName(value = "mall_commodity_specification", autoResultMap = true)
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@Schema(description = "商品规格表")
@AllArgsConstructor
@NoArgsConstructor
public class MallCommoditySpecification extends BaseFormInfo<MallCommoditySpecification> {
    @Serial
    private static final long serialVersionUID = 641655770L;
    @Schema(description = "商品guid")
    private String commodityGuid;
    @Schema(description = "规格名称")
    private String specificationName;
    @Schema(description = "规格图片")
    @TableField(typeHandler = ListStringHandler.class)
    private List<String> specificationCoverList;
    @Schema(description = "销售价格")
    private BigDecimal sellPrice;
    @Schema(description = "成本价格")
    private BigDecimal costPrice;
    @Schema(description = "库存")
    private Integer inventory;
    @Schema(description = "最小起订量")
    private Integer moq;
    @Schema(description = "库存量单位")
    private String sku;
    @NotBlank
    @Schema(description = "产品guid")
    private String infoProductGuid;
    @NotBlank
    @Schema(description = "货币code")
    private String dictCurrencyCode;

    public MallCommoditySpecification(MallCommoditySpecificationDTO commoditySpecificationDTO) {
        Optional.ofNullable(commoditySpecificationDTO).ifPresent(dto -> BeanUtils.copyProperties(dto, this));
    }
}